<?php 
/**
 * Admin的控制器底层文件
 */
class Controller
{
	public $tpl = NULL;
	public $closeCheckLogin = false;
	public function __construct()
	{
		$userInfo = $this->isLogin();
		$this->tpl = Util::getTpl('Admin');
		$this->tpl->assign('loginUserInfo', $userInfo);
		if (!$userInfo && !$this->closeCheckLogin) {
			Util::msgRedirect('您还没有登录', 'Admin/Log');
		}
	}
	
	protected function _closeCheckLogin()
	{
		$this->closeCheckLogin = true;
	}
	
	public function isLogin()
	{
		$uname = Util::getCookies('uname');
		$enpass = Util::getCookies('enpass');
		if ($uname && $enpass){
			$userInfo = AdminUserModule::getUserByUname($uname);
			if ($userInfo && $userInfo['passwd']==$enpass){
				return $userInfo;
			}
			$this->_clearUserCookies();
			return false;
		}
	}
	
	private function _clearUserCookies()
	{
		Util::clearCookies('uname');
		Util::clearCookies('enpass');
		return;
	}
	
	/**
	 * Smarty的$tpl->assign
	 */
	public function assign($var, $val)
	{
		$this->tpl->assign($var, $val);
	}
	
	/**
	 * Smarty的$tpl->display
	 */
	public function display($tpl_name)
	{
		$this->tpl->display($tpl_name);
		exit();
	}
	
	/**
	 * $tpl->fetch
	 */
	public function fetch($tpl_name)
	{
		return $this->tpl->fetch($tpl_name);
	}
	
	public function Show()
	{
		$this->NotFound();
	}
	
	/**
	 * 缺省页面
	 */
	public function NotFound()
	{
		$this->display('Controller/NotFound.html');
	}
	
	public function __call($name, $arguments)
	{
		$this->NotFound();
	}
	
	public function __get($name)
	{
		$this->NotFound();
	}
	
}